Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

feathers-errors

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feathers-errors

Convenient error handling for Feathers services.

  • 0.2.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.8K
increased by1.5%
Maintainers
1
Weekly downloads
 
Created
Source

feathers-errors Build Status

Error handling mixin for Feathers apps.

Getting Started

Feathers errors come with feathers by default. So typically you don't need to install it at all. However you can also use feathers-errors with express directly as well. In that case you install the module with: npm install feathers-errors --save

With Feathers
var feathers = require('feathers');
var memory = require('feathers-memory');

var app = feathers()
    .use('/users', memory)
    .configure(feathers.errors());
With Express
var app = require('express');
var errors = require('feathers-errors');

var app = express()
    .use(errors.fourOhFour)
    .use(errors.handler);

Pro Tip: Just like express middleware, order matters. So your error handling should typically be configured last.

Documentation

Current Error Types:
  • BadRequest: 400
  • NotAuthenticated: 401
  • PaymentError: 402
  • Forbidden: 403
  • NotFound: 404
  • MethodNotAllowed: 405
  • NotAcceptable: 406
  • Timeout: 408
  • Conflict: 409
  • Unprocessable: 422
  • GeneralError: 500
  • NotImplemented: 501
  • Unavailable: 503

Pro Tip: Feathers service adapters (ie. mongodb, memory, etc.) already emit the appropriate errors for you. :-)

Usage:
var feathers = require('feathers');
var app = feathers();

var userService = {
  find: function(params, callback) {

    // If you were to create an error yourself.
    callback(new this.app.errors.NotFound('User does not exist'));

    // You can also simply do something like this if you
    // just want to fire back a simple 500 error with your
    // custom message.
    // 
    // callback('A generic server error');
  },

  setup: function(app){
    this.app = app;
  }
};

app.use('/users', userService)
   .configure(feathers.errors());
404 Handling:

We have conveniently created a basic 404 middleware already for you. If you want to override it, do this:

var feathers = require('feathers');
var app = feathers();

app.use('/users', userService)
   .configure(feathers.errors({
      fourOhFour: function(req, res, next){
        // Handle your 404's some special way
      }
   }));
Custom Error Handling:

We already have an error handler that gets added to the middleware stack when you call feathers.errors(). However, if you want customize how you handle errors you can do so like this:

var feathers = require('feathers');
var app = feathers();

app.use('/users', userService)
   .configure(feathers.errors({
      handler: function(req, res, next){
        // Handle your errors the way you want
      }
   }));

Examples

See examples directory.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

0.2.0

  • Adding support for mongoose errors Issue #5.

0.1.4

  • Adding more error types
  • Changing missing to fourOhFour
  • Making library feathers core compatible

0.1.3

  • Adding a default error page

0.1.2

  • Minor bug fixes

0.1.1

  • Exposing error types directly via var types = require('feathers-errors').types;

0.1.0

  • Initial release

License

Copyright (c) 2014 Eric Kryski Licensed under the MIT license.

Keywords

FAQs

Package last updated on 05 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc